import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/admin'
    },
    {
      path: '/admin/login',
      name: 'admin-login',
      component: () => import('../views/admin/Login.vue')
    },
    {
      path: '/admin',
      name: 'admin-layout',
      component: () => import('../views/admin/Layout.vue'),
      children: [
        {
          path: '',
          redirect: '/admin/users'
        },
        {
          path: 'users',
          name: 'admin-users',
          component: () => import('../views/admin/UserManagement.vue')
        },
        {
          path: 'courses',
          name: 'admin-courses',
          component: () => import('../views/admin/CourseManagement.vue')
        },
        {
          path: 'chapters',
          name: 'admin-chapters',
          component: () => import('../views/admin/ChapterManagement.vue')
        },
        {
          path: 'statistics',
          name: 'admin-statistics',
          component: () => import('../views/admin/Statistics.vue')
        }
      ]
    }
  ]
})

// 路由守卫
router.beforeEach((to, from, next) => {
  next()
})

export default router
